package com.trafficsys.modules.police.Controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trafficsys.modules.entity.DriveCard;
import com.trafficsys.modules.entity.Driver;
import com.trafficsys.modules.entity.Police;
import com.trafficsys.modules.entity.TravelCard;
import com.trafficsys.modules.police.pojo.DriverAndIdCard;
import com.trafficsys.modules.police.pojo.PoliceAndIdCard;
import com.trafficsys.modules.police.service.DriverAndIdCardService;
//import com.trafficsys.modules.police.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@Controller
@RequestMapping("/aqi")
public class DriverAndIdCardController {
    @Autowired(required = false)
    DriverAndIdCardService driverAndIdCardService;


//    @RequestParam("current") int current, @RequestParam("size") int size

    @PostMapping(value = "/driver",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> insertDriver(@RequestBody Driver driver) {
        return driverAndIdCardService.insertDriver(driver);
    }

    @GetMapping("/selectDriverByCardId")
    @ResponseBody
    public IPage<DriverAndIdCard> selectDriverByCardId(@RequestParam("current") int current, @RequestParam("size") int size) {
        Page<DriverAndIdCard> page = new Page<>();
        page.setSize(size);
        page.setCurrent(current);
        return driverAndIdCardService.selectDriverByCardId(page);
    }

    @PutMapping(value = "/updateDriverAndIdCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> updateDriverAndIdCard(@RequestBody DriverAndIdCard driverAndIdCard) {
        return driverAndIdCardService.updateDriverAndIdCard(driverAndIdCard);
    }

    @DeleteMapping("/deleteDriverAndIdCard/{cardId}")
    @ResponseBody
    public HashMap<String, Object> deleteDriverAndIdCard(@PathVariable String cardId) {
        return driverAndIdCardService.deleteDriverAndIdCard(cardId);
    }



    @GetMapping("/getPolice")
    @ResponseBody
    public IPage<PoliceAndIdCard> getPolice(@RequestParam("current") int current, @RequestParam("size") int size){
        Page<PoliceAndIdCard> page = new Page<>();
        page.setSize(size);
        page.setCurrent(current);
        return driverAndIdCardService.getPolice(page);
    }

    @PutMapping(value = "/updatePoliceAndIdCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> updatePoliceAndIdCard(@RequestBody PoliceAndIdCard policeAndIdCard) {
        return driverAndIdCardService.updatePoliceAndIdCard(policeAndIdCard);
    }

    @DeleteMapping("/deletePoliceAndIdCard/{cardId}")
    @ResponseBody
    public HashMap<String, Object> deletePoliceAndIdCard(@PathVariable String cardId) {
        return driverAndIdCardService.deletePoliceAndIdCard(cardId);
    }

    /*
    * {"vin":"45347542355236","brandModel":"保时捷Utrl","carClazz":"大型SUV","carNo":"渝A22237","engineNo":"6754345","fileNo":"3442332","cardId":"500235199805059270","invalidDate":"2031-09-28 19:00:27","state":"在用","travelCarId":"500235199805059270渝A22237","userNature":"民用"}
    * */
    @PostMapping(value = "/travelCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> insertTravelCard(@RequestBody TravelCard travelCard) {
        return driverAndIdCardService.insertTravelCard(travelCard);
    }

    @PutMapping(value = "/updateTravelCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> updateTravelCard(@RequestBody TravelCard travelCard) {
        return driverAndIdCardService.updateTravelCard(travelCard);
    }

    @DeleteMapping("/deleteTravelCard/{carNo}")
    @ResponseBody
    public HashMap<String, Object> deleteTravelCard(@PathVariable String carNo) {
        return driverAndIdCardService.deleteTravelCard(carNo);
    }

    /*
     * 127.0.0.1:8080/aqi/getDriveCard?current=1&size=3
     * */
    @GetMapping("/getDriveCard")
    @ResponseBody
    public IPage<DriveCard> getDriveCard(@RequestParam("current") int current, @RequestParam("size") int size){
        Page<DriveCard> page = new Page<>();
        page.setSize(size);
        page.setCurrent(current);
        return driverAndIdCardService.getDriveCard(page);
    }

    /*
    * http://127.0.0.1:8080/aqi/driveCard
    * {"clazz":"C1","createDate":"2021-09-28 19:00:03","department":"成都交警总队","driveCardId":"500235199855059270C1","cardId":"500235199805059274","nationality":"中国","score":"12","state":"在用","validPeriod":"2027-09-28 19:00:03"}
    * */
    @PostMapping(value = "/driveCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> insertDriverCard(@RequestBody DriveCard driveCard) {
        return driverAndIdCardService.insertDriverCard(driveCard);
    }

    @PutMapping(value = "/updateDriverCard",consumes = "application/json")
    @ResponseBody
    public HashMap<String, Object> updateDriverCard(@RequestBody DriveCard driveCard) {
        return driverAndIdCardService.updateDriverCard(driveCard);
    }

    @DeleteMapping("/deleteDriverCard/{cardId}")
    @ResponseBody
    public HashMap<String, Object> deleteDriverCard(@PathVariable String cardId) {
        return driverAndIdCardService.deleteDriverCard(cardId);
    }
}
